<%@page import="qldc.pm.tienan.constants.TrangThaiTienAnTrongThongKeEnum"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.liferay.portal.kernel.dao.orm.QueryUtil"%>
<%@page import="qldc.pm.tienan.service.DoiTuongTienAnDTOLocalServiceUtil"%>
<%@page import="qldc.pm.tienan.dto.DoiTuongTienAnDTO"%>
<%@page import="com.liferay.portal.kernel.language.LanguageUtil"%>
<%@page import="qldc.pm.qtht.dmdc.utils.DiaChiUtils"%>
<%@page import="java.util.ArrayList"%>
<%@page import="qldc.pm.tienan.model.impl.DoiTuongTienAnImpl"%>
<%@page import="java.util.List"%>
<%@page import="qldc.pm.tienan.service.DoiTuongTienAnLocalServiceUtil"%>
<%@page import="qldc.pm.tienan.model.DoiTuongTienAn"%>
<%@page import="qldc.pm.tienan.service.TienAnLocalServiceUtil"%>
<%@page import="qldc.pm.tienan.model.TienAn"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="qldc.pm.tienan.model.YeuCauTrichLuc"%>
<%@page import="qldc.pm.tienan.service.YeuCauTrichLucLocalServiceUtil"%>
<%@include file="../../init.jsp"%>

<%
String redirect = ParamUtil.getString(request, "redirect");

long yeuCauTrichLucId = ParamUtil.getLong(request, "yeuCauTrichLucId");

YeuCauTrichLuc yeuCauTrichLuc = YeuCauTrichLucLocalServiceUtil.findByYeuCauTrichLucId(yeuCauTrichLucId);

String soSoHoKhau = "";
String hoVaTenNguoiCoTienAn = "";
long noiThuongTruTinhId = 0L;
long noiThuongTruQuanHuyenId = 0L;
long noiThuongTruPhuongXaId = 0L;
String noiThuongTruDiaChi = "";
String soCMND = "";
String soDinhDanhCaNhan = "";
String hoVaTenNguoiYeuCauTrichLuc = "";
String diaChiThuongTruDoiTuong = "";
String ngayDeNghiTraTrichLuc = "";
String ngaySinh = "";

if(Validator.isNotNull(yeuCauTrichLuc)) {
	soSoHoKhau = yeuCauTrichLuc.getSoSoHoKhauDoiTuongTrichLuc();
	hoVaTenNguoiCoTienAn = yeuCauTrichLuc.getHoVaTenDoiTuongTrichLuc();
	noiThuongTruTinhId = yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucTinhId();
	noiThuongTruQuanHuyenId = yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucQuanHuyenId();
	noiThuongTruPhuongXaId = yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucPhuongXaId();
	noiThuongTruDiaChi = yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucDiaChi();
	soCMND = yeuCauTrichLuc.getSoCMNDDoiTuongTrichLuc();
	soDinhDanhCaNhan = yeuCauTrichLuc.getSoDinhDanhCaNhanDoiTuongTrichLuc();
	hoVaTenNguoiYeuCauTrichLuc = yeuCauTrichLuc.getHoVaTenNguoiYeuCauTrichLuc();
	diaChiThuongTruDoiTuong = DiaChiUtils.createBlockDiaChi(yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucTinhId(), yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucQuanHuyenId(), yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucPhuongXaId(), yeuCauTrichLuc.getNoiThuongTruDoiTuongTrichLucDiaChi());
	ngayDeNghiTraTrichLuc = Validator.isNotNull(yeuCauTrichLuc.getNgayDeNghiTraTrichLuc()) ? new SimpleDateFormat("dd/MM/yyyy").format(yeuCauTrichLuc.getNgayDeNghiTraTrichLuc()) : "";
	ngaySinh = Validator.isNotNull(yeuCauTrichLuc.getNgaySinhDoiTuongTrichLuc()) ? new SimpleDateFormat("dd/MM/yyyy").format(yeuCauTrichLuc.getNgaySinhDoiTuongTrichLuc()) : "";
}

List<DoiTuongTienAnDTO> doiTuongTienAns = DoiTuongTienAnDTOLocalServiceUtil.findBySDDCN_CMND_SSHK_HVT_DCTT(soDinhDanhCaNhan, soCMND, soSoHoKhau, hoVaTenNguoiCoTienAn, noiThuongTruTinhId, noiThuongTruQuanHuyenId, noiThuongTruPhuongXaId, noiThuongTruDiaChi, null, null, null, null,null,TrangThaiTienAnTrongThongKeEnum.TAT_CA.getValue(),  QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
if (doiTuongTienAns.size() > 0){
	DoiTuongTienAnDTO doiTuong = doiTuongTienAns.get(0);
	if (Validator.isNull(soDinhDanhCaNhan)){
		soDinhDanhCaNhan = doiTuong.getSoDinhDanhCaNhan();
		soCMND = doiTuong.getSoCMND();
	}
	if (Validator.isNull(diaChiThuongTruDoiTuong)){
		diaChiThuongTruDoiTuong = DiaChiUtils.createBlockDiaChi(doiTuong.getNoiThuongTruTinhId(), doiTuong.getNoiThuongTruQuanHuyenId(), doiTuong.getNoiThuongTruPhuongXaId(), doiTuong.getNoiThuongTruDiaChi());
	}
}

PortletURL troVeURL = renderResponse.createRenderURL();
troVeURL.setParameter("mvcPath", "/html/view.jsp");
troVeURL.setParameter("chonChucNangItem", TienAnConstants.QUAN_LY_YEU_CAU_TRICH_LUC);
%>


<portlet:renderURL var="trichLucRenderUTL">
	<portlet:param name="mvcPath" value="/html/view.jsp"/>
	<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_YEU_CAU_TRICH_LUC %>"/>
	<portlet:param name="tabs1" value="trich_luc_tien_an"/>
	<portlet:param name="redirect" value="<%=redirect %>"/>
	<portlet:param name="yeuCauTrichLucId" value="<%=String.valueOf(yeuCauTrichLucId) %>"/>
</portlet:renderURL>
<table class="gridnormal">
	<tr>
		<td class="txtlabel aui-w20"><liferay-ui:message key="so-dinh-danh-ca-nhan" /></td>
		<td class="aui-w30"><font style="font-weight: bold;"><%=soDinhDanhCaNhan %></font></td>
		<td class="txtlabel aui-w20"><liferay-ui:message key="so-cmnd" /></td>
		<td class="aui-w30"><font style="font-weight: bold;"><liferay-ui:message key="<%=soCMND %>"></liferay-ui:message></font></td>
	</tr>
	
	<tr>
		<td><liferay-ui:message key="ho-va-ten" /></td>
		<td><font style="font-weight: bold;"><%=hoVaTenNguoiCoTienAn %></font></td>
		<td><liferay-ui:message key="ngay-sinh" /></td>
		<td><font style="font-weight: bold;"><%=ngaySinh %></font></td>
	</tr>
	<tr>
		<td><liferay-ui:message key="dia-chi-thuong-tru" /></td>
		<td colspan="3"><font style="font-weight: bold;"><%=diaChiThuongTruDoiTuong %></font></td>
	
	</tr>
	<tr>
		<td><liferay-ui:message key="ho-va-ten-nguoi-yeu-cau-trich-luc" /></td>
		<td><font style="font-weight: bold;"><%=hoVaTenNguoiYeuCauTrichLuc %></font></td>
		<td><liferay-ui:message key="ngay-de-nghi-tra-trich-luc" /></td>
		<td><font style="font-weight: bold;"><%=ngayDeNghiTraTrichLuc %></font></td>
	</tr>
	
	<tr>
		<td></td>
		<td colspan="3">
		<div align="left">
		<%
if (doiTuongTienAns.size() == 0){
%>
			<input type="button" class="btn btn-primary" onclick="javascript:submitForm(document.hrefFm,'<%=trichLucRenderUTL.toString() %>');" value="<liferay-ui:message key="thuc-hien-trich-luc" />" />
		<%} %>
			<input type="button" class="btn" onclick="javascript:submitForm(document.hrefFm,'<%=troVeURL %>');" value="<liferay-ui:message key="tro-ve" />" />
		</div>
		</td>
	</tr>
</table>
<%
if (doiTuongTienAns.size() > 0){
%>
	<h5><liferay-ui:message key="danh-sach-doi-tuong-tien-an-tim-duoc" /></h5>

<liferay-ui:search-container emptyResultsMessage="khong-tim-thay-doi-tuong-tien-an-nao">
	<liferay-ui:search-container-results results="<%=doiTuongTienAns %>" total="<%=doiTuongTienAns.size() %>" />
	<liferay-ui:search-container-row className="qldc.pm.tienan.dto.DoiTuongTienAnDTO" keyProperty="doiTuongTienAnId" modelVar="doiTuongTienAn">
		
		<%-- <portlet:renderURL var="chiTietTienAnUrl">
			<portlet:param name="mvcPath" value="/html/view.jsp" />
			<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_YEU_CAU_TRICH_LUC %>" />
			<portlet:param name="tabs1" value="trich_luc" />
			<portlet:param name="doiTuongTienAnId" value="<%=String.valueOf(doiTuongTienAn.getDoiTuongTienAnId()) %>" />
			<portlet:param name="soDinhDanhCaNhan" value="<%=doiTuongTienAn.getSoDinhDanhCaNhan() %>" />
			<portlet:param name="redirect" value="<%=trichLucRenderUTL.toString() %>" />
			<portlet:param name="yeuCauTrichLucId" value="<%=String.valueOf(yeuCauTrichLucId)%>" />
		</portlet:renderURL> --%>
		
		<portlet:renderURL var="trichLucTienAnURL">
			<portlet:param name="mvcPath" value="/html/view.jsp" />
			<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_YEU_CAU_TRICH_LUC %>" />
			<portlet:param name="tabs1" value="trich_luc_tien_an" />
			<portlet:param name="doiTuongTienAnId" value="<%=String.valueOf(doiTuongTienAn.getDoiTuongTienAnId()) %>" />
			<portlet:param name="soDinhDanhCaNhan" value="<%=doiTuongTienAn.getSoDinhDanhCaNhan() %>" />
			<portlet:param name="redirect" value="<%=trichLucRenderUTL.toString() %>" />
			<portlet:param name="danhSachUrl" value="<%=redirect.toString() %>" />
			<portlet:param name="yeuCauTrichLucId" value="<%=String.valueOf(yeuCauTrichLucId)%>" />
		</portlet:renderURL>
		
		<%
			String diaChiThuongTru = DiaChiUtils.createBlockDiaChi(doiTuongTienAn.getNoiThuongTruQuanHuyenId(), doiTuongTienAn.getNoiThuongTruPhuongXaId(), doiTuongTienAn.getNoiThuongTruDiaChi());
		
			String chiTiecTienAnLink = "javascript:submitForm(document.hrefFm,'" + trichLucTienAnURL.toString() + "');";
		%>
	
		<liferay-ui:search-container-column-text name="ho-va-ten" property="hoVaTen" />
		<liferay-ui:search-container-column-text name="so-dinh-danh-ca-nhan" property="soDinhDanhCaNhan" orderable="<%=true %>" orderableProperty="soDinhDanhCaNhan" />
		<liferay-ui:search-container-column-text name="so-so-ho-khau" property="soSoHoKhau" />
		<liferay-ui:search-container-column-text name="noi-thuong-tru" value="<%=diaChiThuongTru %>" />
		<liferay-ui:search-container-column-text name="toi-danh" property="toiDanh" />
		<liferay-ui:search-container-column-text name="ngay-pham-toi" property="ngayPhamToi" />
		
		<liferay-ui:search-container-column-button cssClass="thuc-hien-trich-luc-btn" href="<%=chiTiecTienAnLink %>" name="thuc-hien-trich-luc" />
	</liferay-ui:search-container-row>
	
	<liferay-ui:search-iterator paginate="<%=false %>"/>
	
</liferay-ui:search-container>
<% }
else {
	%>
	<h5><liferay-ui:message key="khong-tim-thay-doi-tuong-tien-an-nao-thoa-dieu-kien" /></h5>
<%}
%>

